import service from '../api'

// 搜索用户
export function searchUser(query, showLoading = true) {
    let uri = `auth/search_user?account=${query}&nickname=${query}&phone=${query}`
    return service.get(uri, {
        showLoading: showLoading
    })
}
// 聘用人员到某角色下
export function employUserToRole(data, showLoading = true) {
    let uri = 'auth/role_employ'
    return service.post(uri, data, {
        showLoading: showLoading
    })
}
// 角色下的人员解聘
export function dismissUserToRole(data, showLoading = true) {
    let uri = 'auth/role_dismiss'
    return service.post(uri, data, {
        showLoading: showLoading
    })
}
// 通过组织机构ID得到组织机构的权限
export function getGroupPermissionList(pk, showLoading = true) {
    let uri = `auth/empower_group_permission/${pk}`
    return service.get(uri, {
        showLoading: showLoading
    })
}
// 提交组织机构的权限修改
export function submitGroupPermission(pk, data, showLoading = true) {
    let uri = `auth/empower_group_permission/${pk}`
    return service.put(uri, data, {
        showLoading: showLoading
    })
}
// 通过角色ID得到角色的权限
export function getRolePermissionList(pk, showLoading = true) {
    let uri = `auth/empower_role_permission/${pk}`
    return service.get(uri, {
        showLoading: showLoading
    })
}
// 提交角色的权限修改
export function submitRolePermission(pk, data, showLoading = true) {
    let uri = `auth/empower_role_permission/${pk}`
    return service.put(uri, data, {
        showLoading: showLoading
    })
}



// 提交权限修改
export function permissionSubmit(data, showLoading = true) {
    let uri = `auth/permission_handle`
    return service.post(uri, data, {
        showLoading: showLoading
    })
}
// 组织
export function groupList(showLoading = true) {
    let uri = 'auth/group'
    return service.get(uri, {
        showLoading: showLoading
    })
}
export function createGroup(data, showLoading = true) {
    let uri = 'auth/group'
    return service.post(uri, data, {
        showLoading: showLoading
    })
}
export function updateGroup(id, data, showLoading = true) {
    let uri = `auth/group/${id}`
    return service.patch(uri, data, {
        showLoading: showLoading
    })
}
export function deleteGroup(pk, showLoading = true) {
    let uri = `auth/group/${pk}`
    return service.delete(uri, {
        showLoading: showLoading
    })
}
// 角色
export function roleList(showLoading = true) {
    let uri = 'auth/role'
    return service.get(uri, {
        showLoading: showLoading
    })
}
export function createRole(data, showLoading = true) {
    let uri = 'auth/role'
    return service.post(uri, data, {
        showLoading: showLoading
    })
}
export function updateRole(id, data, showLoading = true) {
    let uri = `auth/role/${id}`
    return service.patch(uri, data, {
        showLoading: showLoading
    })
}
export function deleteRole(pk, showLoading = true) {
    let uri = `auth/role/${pk}`
    return service.delete(uri, {
        showLoading: showLoading
    })
}
// 组织及角色树形结构
export function getSideTreeData(showLoading = true) {
    let uri = 'auth/group_role_tree'
    return service.get(uri, {
        showLoading: showLoading
    })
}

// export function remove(uri, key, showLoading = true) {
//     let url = `${uri}/${key}`
//     return service.delete(url, {}, { showLoading: showLoading })
// }
// export function retrieve(uri, key, showLoading = true) {
//     let url = `${uri}/${key}`
//     return service.get(url, { showLoading: showLoading })
// }
// export function create(uri, data, showLoading = true) {
//     return service.post(uri, data, { showLoading: showLoading })
// }
// export function put(uri, key, data, showLoading = true) {
//     let url = `${uri}/${key}`
//     return service.put(url, data, { showLoading: showLoading })
// }
// export function patch(uri, key, data, showLoading = true) {
//     let url = `${uri}/${key}`
//     return service.put(url, data, { showLoading: showLoading })
// }